package com.fundboss.display;


import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;
import java.util.Map;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.Border;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import org.jfree.ui.HorizontalAlignment;
import org.jfree.ui.VerticalAlignment;

import model.market.MarketConfig;
import model.market.MarketException;
import model.market.MarketListener;
import model.market.ModelResults;


public class ParameterEntryPanel extends JPanel{

	//List<Checkbox> boxes;
	//
	JButton button =new JButton("Go!!");
	
	public ParameterEntryPanel(final TestApplet parent){
		
		GridBagLayout layout = new GridBagLayout();
		setLayout(layout);
		GridBagConstraints constraints = new GridBagConstraints();
		constraints.fill = GridBagConstraints.BOTH;
		constraints.weightx=0;
		constraints.weighty=0;
		constraints.ipadx=8;
		constraints.ipady=8;
		constraints.insets=new Insets(5,5,5,5);
		constraints.gridwidth=GridBagConstraints.REMAINDER;
		
		JPanel topPanel = new JPanel();
		topPanel.setLayout(new BorderLayout());
		//topPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
		
		JPanel instructionWrapper = new JPanel();
		instructionWrapper.setLayout(new GridLayout(1,3));
		try {
			URL url = new java.net.URL(parent.getCodeBase(), "logosmall.png");
			if (url == null)
				throw new Exception("url == null");
			Image image = parent.getImage(url);
			if (image == null)
				throw new Exception("l_Image == null");
			JLabel imageLabel = new JLabel(new ImageIcon(image));
			imageLabel.setHorizontalAlignment(JLabel.LEFT);
			instructionWrapper.add(imageLabel);
		} catch (Exception a_Exception) {
			//who cares, suppres.
		}

//		JLabel instruction = new JLabel(
//				"Please configure the market run below, and when you are ready click 'Go'!");
//		//instruction.setHorizontalAlignment(JLabel.LEFT);
//		instructionWrapper.add(instruction);
		
		
		
		
		topPanel.add(instructionWrapper,BorderLayout.CENTER);
		
		final MarketConfig config = new MarketConfig();
		final TraderConfig traderConfig= new TraderConfig();
		
		button.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				
				parent.kickOffMarket(config,traderConfig);
				//button.setEnabled(false);
			}
		});
		JPanel buttonWrapper =new JPanel();
		buttonWrapper.setLayout(new BorderLayout());
		button.setFont(new Font(null,Font.PLAIN,18));
		button.setMargin(new Insets(10,20,10,20));
		button.setVerticalAlignment(JButton.CENTER);
		JPanel buttonwrapper2 = new JPanel();
		buttonwrapper2.add(button);
		buttonWrapper.add(buttonwrapper2,BorderLayout.EAST);
		//buttonWrapper.add(statusLabel,BorderLayout.CENTER);
		
		topPanel.add(buttonWrapper,BorderLayout.EAST);
		
		add(topPanel,constraints);
		
		
		
		constraints.gridwidth= GridBagConstraints.RELATIVE; 
		
		
		TradersParamPanel traders = new TradersParamPanel(config,traderConfig);
		
		JPanel wrapper =new JPanel();
		wrapper.setLayout(new BorderLayout());
		wrapper.add(traders,BorderLayout.NORTH);
		wrapper.add(new JPanel(),BorderLayout.CENTER);
		add(wrapper,constraints);
		
		constraints.gridwidth=GridBagConstraints.REMAINDER;
		
		AssetsParamPanel assets = new AssetsParamPanel(config);
		wrapper =new JPanel();
		wrapper.setLayout(new BorderLayout());
		wrapper.add(assets,BorderLayout.NORTH);
		wrapper.add(new JPanel(),BorderLayout.CENTER);
		add(wrapper,constraints);
		
		constraints.gridwidth= GridBagConstraints.RELATIVE; 
		
		MarketParamPanel marketParams = new MarketParamPanel(config);
		wrapper =new JPanel();
		wrapper.setLayout(new BorderLayout());
		wrapper.add(marketParams,BorderLayout.NORTH);
		wrapper.add(new JPanel(),BorderLayout.CENTER);
		add(wrapper,constraints);
		
		constraints.gridwidth=GridBagConstraints.REMAINDER;
		
		TimeParamPanel advancedParams = new TimeParamPanel(config);
		wrapper =new JPanel();
		wrapper.setLayout(new BorderLayout());
		wrapper.add(advancedParams,BorderLayout.NORTH);
		wrapper.add(new JPanel(),BorderLayout.CENTER);
		add(wrapper,constraints);
		
		constraints.gridwidth= GridBagConstraints.RELATIVE; 
		
		AdvancedParamPanel advanced = new AdvancedParamPanel(config);
		
		wrapper =new JPanel();
		wrapper.setLayout(new BorderLayout());
		wrapper.add(advanced,BorderLayout.NORTH);
		wrapper.add(new JPanel(),BorderLayout.CENTER);
		add(wrapper,constraints);
		
		constraints.gridwidth=GridBagConstraints.REMAINDER;
		
		wrapper =new JPanel();
		wrapper.setLayout(new BorderLayout());
		wrapper.add(new SpecialParamPanel(config),BorderLayout.CENTER);
		add(wrapper,constraints);
		
		constraints.weightx=1;
		constraints.weighty=1;
		
		constraints.gridwidth=GridBagConstraints.REMAINDER;
		
		add(new JPanel(),constraints);
		
		
		
		
	}

	
	
}

